<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.List"%>
<%@page import="org.nado.bbs.BBSBoardVO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("UTF-8");
%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>

<base href="../resources/" />
<meta http-equiv="content-type" content="text/html; charset= UTF-8" />
<title>BBS by nado</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link rel="stylesheet" type="text/css" href="style/style.css" />

<style type="text/css">
table {
	width: 500px;
	border-collapse: collapse;
	text-align: center;
	font-family: 'Trebuchet MS';
}

td,th {
	font-size: 10pt;
	border: 1px solid #ffffff;
	height: 30px;
}

th {
	background-color: #aaaaaa;
	color: #ffffff;
	font-family: Georgia;
}

tr.alt td {
	color: #111111;
	background-color: #dcdcdc;
}
</style>

</head>
<body>

<div id="main">
<div id="main_inner" class="fixed">
<div id="primaryContent_2columns">
<div id="columnA_2columns">
	<h3>BBS</h3>
	<p>
	<table>
		<tr>
			<th>No</th>
			<th>Title</th>
			<th>Writer</th>
			<th>RegDate</th>
			<th>Count</th>
		</tr>
		
<!-- 		1. EL Style 리스트 출력 -->

<%-- 		<c:forEach var="BBSList" items="${BBSList}"> --%>
<%-- 			<td>${BBSList.bbs_no}</td> --%>
<!-- 			<td style="text-align: left"> -->
<%-- 				<a href="/web/bbs/read?bbs_no=${BBSList.bbs_no}&page_no=${page_no}" style="text-decoration: none">  --%>
<%-- 				<c:if test="${BBSList.bbs_depth != '0'}"> --%>
<%-- 					<c:forEach begin="1" end="${BBSList.bbs_depth}"> --%>
<!-- 										Re: -->
<!-- 					┗ -->
<%-- 					</c:forEach> --%>
<%-- 				</c:if> ${BBSList.bbs_title} (${BBSList.bbs_recnt}) --%>
<!-- 				</a></td> -->
<%-- 			<td>${BBSList.bbs_writer}</td> --%>
<%-- 			<td><c:set var="date" value="${BBSList.bbs_regDate}" />  --%>
<%-- 			<fmt:formatDate	value="${date}" pattern="yyyy/MM/dd" /></td> --%>
<%-- 			<td>${BBSList.bbs_readcnt}</td> --%>
<%-- 		</c:forEach> --%>

		<%
		// 2. java style 리스트 출력
		
		int page_no = (Integer) request.getAttribute("page_no");
		List<BBSBoardVO> list = (List<BBSBoardVO>) request.getAttribute("searchList");
		for(BBSBoardVO vo: list){
			%>
		<tr>
			<td><%=vo.getBbs_no()%></td>
			<td><a href="/web/bbs/read?bbs_no=<%=vo.getBbs_no()%>&page_no=<%=page_no%>" 
			style="text-decoration: none">
			<%
			if(vo.getBbs_depth() != 0){
				for(int i = 0; i < vo.getBbs_depth(); i++){
					out.write("┗");
				}
			}
			%>
			<%=vo.getBbs_title()%></a></td>
			<td><%=vo.getBbs_writer()%></td>
			<%
			SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
			%>
			<td><%=format.format(vo.getBbs_regDate())%></td>
			<td><%=vo.getBbs_readcnt()%></td>
		</tr>
			<%
		}
		%>
		<tr>
		<td style="text-align: left" colspan="3"><br></br>
			<form action="/web/bbs/search/page_no=1" method="post">
			<select name="type">
				<option value="bbs_title">제목</option>
				<option value="bbs_content">내용</option>
				<option value="bbs_writer">작성자</option>
			</select>
			<input type="text" name="keyword" size="20" required="required"></input>
			<input type="submit" value="검색"></input>
			</form></td>
			
		<td style="text-align: right" colspan="2">
			<br></br>
			
			<%
			// 리스트 페이징
			int initPage = -1;
			int maxPage = -1;

			maxPage = (int) Math.ceil(list.get(0).getBbs_totalcnt()/(double)10); 
			initPage = (int) (Math.ceil(page_no/(double)10) *10) -9;
		
			System.out.println("maxPage: " + maxPage);
			System.out.println("initPage: " + initPage);
			
			if(initPage != 1){
				%>
				<a href="/web/bbs/list?page_no=<%=initPage - 1 %>" 
				style="text-decoration: none"> << </a>
				<%
			}
			for(int i = initPage; i <= maxPage; i++){
				if(i == (initPage+10)){
						%>
						<a href="/web/bbs/list?page_no=<%=initPage + 10 %>" 
						style="text-decoration: none"> >> </a>
						<%
					break;
				}else{
					if(i == page_no){
						out.write("["+i+"]");
					}else{
					%>
					<a href="/web/bbs/list?page_no=<%=i %>" 
					style="text-decoration: none">[<%=i %>] </a>
					<%
					}
				}
			}
			%>
			<form action="/web/bbs/write" method="post">
			<input type="submit" name="write" value="글쓰기"></input>
			</form>
		</td>
		</tr>
	</table>
	</p>
</div>
</div>
</div>
</div>
</body>
</html>